-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support the "file" URI scheme #7526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as in comment
Surely this has all the same problems as OSC 7 (#3158)? Realistically it's most likely going to be used in a WSL shell, so the file path will be in the WSL filesystem, and thus won't be understood by ShellExecute. Until we have a way to appropriately convert file paths based on the active shell, this just doesn't seem practical. Also, using ShellExecute on a file url seems risky from a security point of view. If the file path points to an executable then that executable is going to be run. I'm not sure how much damage could be done that way, but I wouldn't feel comfortable knowing an attacker could run any executable on my system just by tricking me into clicking somewhere. |
From security point of view, I expect Windows Security or third party vendors for A/V, FW, HIDS/HIPS to handle the protection. Additionally there's a ransomware setting that basically denies all executables from doing anything to protected parts of the filesystem. Its not completely up to WT to handle the security here. People want this functionality and should understand the security implications. If there's a more secure way for files to get opened including executables then great. Just as long as it's understood we're inheriting most of the security from Windows. |
#7420 should land before this, so that people can see what they are going to be clicking on. |
EDIT: Nevermind, there are too many types of executables to account for |
I agree with this. Dialogs by default with a setting to disable the dialog and simply run the executable. |
technically we also have to consider scripts as well. Malicious programs written in go, python, ruby, etc can still run if the programming language is installed |
No. |
@j4james Alright, I finally get to come back with a bit of an answer to this.
We chatted with the defender/application security folks about this. At the end of the day, Looking at it all-up:
I'm less concerned about the security aspect of this feature. Now- for WSL paths. "Works predictably for 15% of applications" (h/t to PhMajerus' AXSH, and other on-Windows requestors) is better in so many ways than "Works for 0% of applications", in my estimation. Incremental progress 😄 while we work on features that'll make it even more broadly applicable. I'm inclined to call in favor of merging this. |
{ | ||
return true; | ||
} | ||
// TODO: by the OSC 8 spec, if a hostname (other than localhost) is provided, we _should_ be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be filing a follow-up for this? I'd imagine that this would involve returning a different URL that the one emitted. That would let the client emit file://localhost/foo/bar
, and then let us ShellExecute
file://foo/bar
.
I'm still not completely comfortable with this myself, but if your security folk are satisfied that it's not going to be a problem, then that is at least some reassurance. For those of us that are more paranoid, it might be nice to have an option to disable some or all of the hyperlink functionality, but that could always be a follow-up PR. |
Do we have a separate issue for the auto-hyperlinking of plain file paths, for example I observed an interesting behavior in iTerm2 (I just really used iTerm2 a lot back in the days as iOS developer): it actually detects if the file path is legal before hyperlinking it. For example, if the path is |
Inspired by #8166 (comment), we can also make the result of |
if (_IsUriSupported(parsed)) | ||
{ | ||
ShellExecute(nullptr, L"open", eventArgs.Uri().c_str(), nullptr, nullptr, SW_SHOWNORMAL); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use the "edit" verb here for file URLs? Perhaps having two separate conditions, like IsUriSupportedForOpen
, and IsUriSupportedForEdit
. Because if a user is clicking on a link to a .py
file, I think it's more likely they would want the file edited rather than executed (which is what the open verb tends to do).
I don't know if there are any downsides to using the edit verb though. I did bring this up in the #7562 discussion thread, but I don't think anyone commented on the merits of the idea one way or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in love with the idea of using the edit verb. I just gave it a test on a couple of the files I had laying around:
extension | open behavior | edit behavior |
---|---|---|
ps1 | notepad | powershell ISE (?!) |
txt | notepad | notepad |
cpp | visual studio preview, which is not my default VS (argh) | notepad |
no extension | "how do you want to open this?" dialog | an error message from ShellExecute |
.gitconfig, .wslconifg, etc | same as above | same as above |
It's great if somebody's registered for it, but I'm bothered that the OS doesn't give it the same "do what with?" treatment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extensions that concerned me were things like .py
, .cmd
, .bat
, and .vbs
. In all cases, the open verb executed the script, and the edit
verb opened the file in notepad. Those all seem like files that would not be good to execute when you click on them.
If we're worried about the cases where a file extension doesn't have a registered handler, maybe we can handle that as a special case check. But wanting to click on a link to a file that you've never registered a handler for, seems a far less likely use case than clicking on something like a .py
file, and expecting to be able to edit it.
Although maybe I'm the odd one out here. I just assumed nobody would want scripts to execute when clicking on their links.
Misspellings found, please review:
To accept these changes, run the following commands from this repository on this branch
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbage and it relates to a binary-ish string, please add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
I'm going to merge this with no backport to get Preview into the hands of more folks who can help us evaluate whether this is a risk and if we should back it out or restrict it further. I do, though, hear & value James' concerns about autoexecuting a script on click(!) |
🎉 Handy links: |
Does two things related to URLs emitted via OSC8. * Allows `wsl$` and `wsl.localhost` as the hostname in `file://` URIs * Generally allows _all_ URIs that parse as a URI. The relevant security comments: #7526 (comment) > this doesn't let a would-be attacker specify command-line arguments (ala "cmd.exe /s /c do_a_bad_thing") (using somebody else's reputation to cause mayhem) > > `ShellExecute` de-elevates because it bounces a launch request off the shell > > "Works predictably for 15% of applications" (h/t to PhMajerus' AXSH, and other on-Windows requestors) is better in so many ways than "Works for 0% of applications", in my estimation. Incremental progress 😄 while we work on features that'll make it even more broadly applicable. Closes #10188 Closes #7562
Does two things related to URLs emitted via OSC8. * Allows `wsl$` and `wsl.localhost` as the hostname in `file://` URIs * Generally allows _all_ URIs that parse as a URI. The relevant security comments: #7526 (comment) > this doesn't let a would-be attacker specify command-line arguments (ala "cmd.exe /s /c do_a_bad_thing") (using somebody else's reputation to cause mayhem) > > `ShellExecute` de-elevates because it bounces a launch request off the shell > > "Works predictably for 15% of applications" (h/t to PhMajerus' AXSH, and other on-Windows requestors) is better in so many ways than "Works for 0% of applications", in my estimation. Incremental progress 😄 while we work on features that'll make it even more broadly applicable. Closes #10188 Closes #7562 (cherry picked from commit 65640f6) Service-Card-Id: 88719284 Service-Version: 1.17
We now support the file URI schemes where the hostname is either
"localhost" or the empty string
References #5001
Fixes #7699